'''
A TwistedSim tutorial on how to host asyncore application under TwistedSim
using process-based emulation.

@author: Hatem Oraby
'''
import twistedSim.simManager as simManager 
from twistedSim.contextHandlers import ProcessHandler
from twistedSim.moduleHandler import asyncoreH


def main():
    machine = simManager.Machine()
    #server
    server = ProcessHandler('asyncore-example-2.py', handler = asyncoreH(),
                            nickName = "Asyncore Server")
    simManager.SimManager.addModule(server,machine)
    
    #client
    client = ProcessHandler('asyncore-example-1.py', startTime = 100,
                            handler = asyncoreH(), 
                            nickName = "Asyncore Client")
    simManager.SimManager.addModule(client,machine)
    
    simManager.SimManager.run()

if __name__ == '__main__':
    main()